/**
 * Created by zhr on 2017/6/27.
 */
import React from "react";
import Relay from 'react-relay';
import { message } from 'antd';
import Util from "../../../../../../../util/Util";
import { Button, Modal, Input } from 'fly';
import './common.css';
import Config from "../../../../../../../util/Config"


export default class Tab extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            replyDetailVisible: false,
            examineList:null,
            Inx: null
        }
        this.url = Config.qiuniu;
        this.handleOk = this.handleOk.bind(this);
        this.handleCancel = this.handleCancel.bind(this);
    }

    handleOk() {
        this.setState({
            replyDetailVisible: false,
        });
    }
    handleCancel() {
        this.setState({
            replyDetailVisible: false,
        })
    }
    fileDownload(v) {
        // Array.isArray(JSON.parse(v)) && JSON.parse(v).forEach((i, k) => {
        const h = this.url + v.response.key + `?attname=`+ v.name, a = document.createElement("a");
        a.href = h;
        a.setAttribute("download","");
        a.click();
        // });
    }
    showFile(fileJSON) {
        return fileJSON && fileJSON.length >= 1? (
            JSON.parse(fileJSON).map((f,c)=>{
                return (
                    <span className="settlementView_for">
                        <a style={{cursor:'default'}}>{f.name}</a>
                        {
                            f.response ? (<a onClick={this.fileDownload.bind(this,f)} style={{minWidth:'30px',color:'#36b3b3',paddingLeft: '0',marginLeft: '50px'}}>下载</a>) : null
                        }
                    </span>)
            })
        ) :  '无'
    }
    render() {
        const {examineList, Inx} = this.state;
        return (
            <div className="">
                <Modal
                    title="批复详情"
                    visible={this.state.replyDetailVisible}
                    onOk={this.handleOk}
                    onCancel={this.handleCancel}
                    footer={null}
                >
                    <div>
                        {
                            examineList && examineList.length ? (
                                <div className="reply_box">
                                    <p>
                                        <span>时&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 间：</span>
                                        <span>{examineList && Util.dateFormat(examineList[Inx].examineDate)}</span>
                                    </p>
                                    <p>
                                        <span>企&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 业：</span>
                                        <span>{examineList && examineList[Inx].examineCompany}</span>
                                    </p>
                                    <p>
                                        <span>批复结果：</span>
                                        <span>{examineList && examineList[Inx].result == 1 ? '接受' :'不接受'}</span>
                                    </p>
                                    <p>
                                        <span style={{float:'left'}}>附&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;件：</span>
                                        <span>
                                                {
                                                    this.showFile(examineList && examineList[Inx].fileJSON)
                                                }
                                        </span>
                                    </p>
                                    <p>
                                        <span>批复说明：</span>
                                        <span>{(examineList && examineList[Inx].explainDesc) || '无'}</span>
                                    </p>
                                </div>
                            ) : null
                        }
                    </div>
                </Modal>
            </div>
        )
    }
}